package cn.example.query;

import cn.example.pojo.Business;
import cn.example.pojo.Food;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.Data;

@Data
public class FoodQuery extends BaseQuery {

    private String foodName;  //餐品名称搜索条件
    private Integer businessId; //商家编号

//    @Override
//    public QueryWrapper getQueryWrapper() {
//        QueryWrapper<Food> queryWrapper = new QueryWrapper<>();
//        if(StringUtils.isEmpty(foodName)){
//            queryWrapper.like("foodName",foodName);
//        }
//        if(businessId != null && businessId != 0){
//            queryWrapper.eq("f.businessId",businessId);
//        }
//        return queryWrapper;
//    }


    @Override
    public Wrapper getQueryWrapper() {
        MPJLambdaWrapper<Food> queryWrapper = new MPJLambdaWrapper<Food>()
                .setAlias("f")
                .selectAll(Food.class,"f")
                .selectAs(Business::getBusinessName,"'business.businessName'")
                .selectAs(Business::getBusinessAddress,"'business.businessAddress'")
                .leftJoin(Business.class,"b",Business::getBusinessId,Food::getBusinessId)
                .orderByDesc("foodId");
        //搜索条件
        if(StringUtils.isNotEmpty(foodName)){
            queryWrapper.like("foodName",foodName);
        }
        if(businessId != null && businessId != 0){
            queryWrapper.eq("f.businessId",businessId);
        }
        return queryWrapper;
    }
}
